import Vue from 'vue'
import App from './App.vue'
import router from '@/router/index'
import Mint from 'mint-ui';
import store from '@/store/index'
import pageAuto from '@/assets/unit/rem'
import {lc} from '@/assets/unit/index'
import filters from '@/filter/index'
import { Toast } from 'mint-ui';
import { Indicator } from 'mint-ui';
import Api from '@/assets/api/index';
import qrcode from 'lc-qrcodedecode';

pageAuto();

//注册过滤器,如果需要用的话
lc.deepCopy(filters,function (item,val) {
  Vue.filter(item,val);
});

Vue.prototype.Toast = Toast;
Vue.prototype.dev = (function(){
    let u =navigator.userAgent;
    if(u.indexOf('Android') > -1 || u.indexOf('Adr') > -1)return 'android';
    if(!!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/))return 'IOS';
    return 'other';
})();

Vue.config.productionTip = false;

Vue.use(Mint);


Vue.use(qrcode);

window['setToken'] = function (token){
  if(sessionStorage.getItem('token'))return;
  sessionStorage.setItem('token',token || '');
};
window['getSearch']=function(str){
    let res;
    let search = location.search.slice(1).split('&');
    search.forEach(function (item,index){
        let temp = item.split('=');
        if(str == temp[0]){
          res = temp[1];
        }
    });
    return res;
};
sessionStorage.setItem('ver','show');
setToken(getSearch('token'));
// setToken('533e7f665e5772891742f14b4e1bfc41');

// window['saveKey'] = function (key){
//     if(sessionStorage.getItem(key))return;
//     sessionStorage.setItem(key,getSearch(key));
// };
// saveKey("rentId");
// saveKey("regionId");

window['fillStr'] = function (res) {
  // 待测试
  const userInfo = JSON.parse(sessionStorage.getItem('userInfo'));
  if(res.split('#').length > 0){
    Api.scanCodeBindForShop({
      bindDesc:'店主端',
      bindMarks:'店主端',
      userId:userInfo.userId,
      userRentId:userInfo.userRentId,
      userOpenId:res.split('#')[1]
    }).then(function (data){
        Toast('绑定成功！');
      },function (err) {
      });
  }else{
    Toast('扫描失败，请稍后重试！');
  }
};

window['checkToken'] = function (data){
  if(data.code == -1){
    getToken(false);
    return false;
  }
  return true;
};

window['upCode'] = function (str){

};



window['copyCb'] = function (code) {
  if(code == 1){
    Toast('复制成功');
  }else if(code ==2){
    Toast('复制失败，请重试！');
  }
};
//     getToken(true);


let obj = query() || '';
sessionStorage.setItem('lcInfo',JSON.stringify(obj));

function query(){
  if(sessionStorage.getItem('lcInfo')){
      return JSON.parse(sessionStorage.getItem('lcInfo'));
  }
  let result = {};
  if(location.search){
    var Tempurl = location.search.slice(1).split('&');
  }else{return;}
  let len = Tempurl.length;
  for (let i  =0;i<len;i++) {
    let tempData = Tempurl[i].split('=');
    result[tempData[0]] = tempData[1];
  }
  return result;
}

router.beforeEach((to, from, next) => {
  Indicator.close();
  next();
});
  document.getElementById('lyf').style.display = 'none';


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
});
